import { service } from '@/utils/axios'

const BASE_URL = '/v1/roles'
// 新增
export function addRole(data: any): Promise<any> {
  return service({
    url: BASE_URL,
    method: 'post',
    data
  })
}

// 更新
export function updateRole(id: any, data: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${id}`,
    method: 'put',
    data
  })
}

export function deleteRole(ids: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${ids}`,
    method: 'delete'
  })
}

export function getRolesList(params: any) {
  return service({
    url: BASE_URL,
    method: 'get',
    params
  })
}

export function getRoleOptionList(): any {
  return service({
    url: `${BASE_URL}/options`,
    method: 'get'
  })
}

export function getRolePageList(data: any) {
  return service({
    url: `${BASE_URL}/page`,
    method: 'get',
    params: data
  })
}

export function getRoleForm(id: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${id}/form`,
    method: 'get'
  })
}

export function updateRoleStatus(id: any, status: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${id}/status`,
    method: 'put',
    params: {
      status: status
    }
  })
}

// 获取角色的菜单ID集合
export function getMenuListByRole(roleId: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${roleId}/menuIds`,
    method: 'get'
  })
}

// 获取角色的菜单ID集合
export function assignMenusToRole(roleId: any, menuIds: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${roleId}/menus`,
    method: 'put',
    data: {
      menuIds: menuIds
    }
  })
}
